package construction.proxy.jdk;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {

    Object getProxyInstance(ITeacherDao target){

        //Object newProxyInstance(ClassLoader loader,Class<?>[] interfaces,InvocationHandler h)
        var obj = Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        return method.invoke(target,args);
                    }
                }
        );
        return obj;
    }

}
